<template>
  <div class="modern-list-container">
    <!-- 主内容区域 -->
    <div v-if="showFlag" class="modern-list-content">
      <!-- 工具栏 -->
      <div class="modern-toolbar">
        <!-- 搜索区域 -->
        <div class="modern-search-panel">
          <el-form class="modern-search-form">
            <div class="search-group">
              <el-input
                v-model="searchForm.xiquName"
                placeholder="知识名称"
                class="modern-input"
                prefix-icon="el-icon-search"
                clearable
              >
              </el-input>

              <el-select
                v-model="searchForm.xiquTypes"
                placeholder="知识类型"
                class="modern-select"
              >
                <el-option label="全部类型" value=""></el-option>
                <el-option
                  v-for="(item, index) in xiquTypesSelectSearch"
                  :key="index"
                  :label="item.indexName"
                  :value="item.codeIndex"
                ></el-option>
              </el-select>

              <el-input
                v-model="searchForm.yonghuName"
                placeholder="用户姓名"
                class="modern-input"
                prefix-icon="el-icon-user"
                clearable
              >
              </el-input>

              <el-button
                type="primary"
                class="modern-search-btn"
                @click="search"
              >
                <i class="el-icon-search"></i>
                查询
              </el-button>
            </div>
          </el-form>
        </div>
        <!-- 操作按钮组 -->
        <div class="action-toolbar">
          <div class="action-group">
            <el-button-group>
              <el-tooltip
                content="新增收藏"
                v-if="isAuth('xiquCollection', '新增')"
              >
                <el-button
                  type="success"
                  icon="el-icon-star-off"
                  class="modern-action-btn"
                  @click="addOrUpdateHandler()"
                  >新增</el-button
                >
              </el-tooltip>

              <el-tooltip
                content="批量删除"
                v-if="isAuth('xiquCollection', '删除')"
              >
                <el-button
                  type="danger"
                  icon="el-icon-delete"
                  class="modern-action-btn"
                  :disabled="dataListSelections.length <= 0"
                  @click="deleteHandler()"
                  >删除</el-button
                >
              </el-tooltip>

              <el-tooltip
                content="数据洞察"
                v-if="isAuth('xiquCollection', '报表')"
              >
                <el-button
                  type="warning"
                  icon="el-icon-data-analysis"
                  class="modern-action-btn"
                  @click="chartDialog()"
                  >报表</el-button
                >
              </el-tooltip>

              <el-tooltip
                content="下载模板"
                v-if="isAuth('xiquCollection', '导入导出')"
              >
                <a class="modern-link-btn" :href="templateUrl">
                  <el-button
                    type="info"
                    icon="el-icon-download"
                    class="modern-action-btn"
                    >模板</el-button
                  >
                </a>
              </el-tooltip>

              <el-upload
                v-if="isAuth('xiquCollection', '导入导出')"
                :action="getActionUrl"
                :show-file-list="false"
                class="inline-upload"
              >
                <el-tooltip content="批量导入">
                  <el-button
                    type="primary"
                    icon="el-icon-upload"
                    class="modern-action-btn"
                    >导入</el-button
                  >
                </el-tooltip>
              </el-upload>

              <el-tooltip
                content="导出数据"
                v-if="isAuth('xiquCollection', '导入导出')"
              >
                <download-excel class="inline-export">
                  <el-button
                    type="success"
                    icon="el-icon-download"
                    class="modern-action-btn"
                    >导出</el-button
                  >
                </download-excel>
              </el-tooltip>
            </el-button-group>
          </div>
        </div>
      </div>

      <!-- 数据表格 -->
      <div class="modern-table-wrapper">
        <el-table
          :data="dataList"
          class="modern-data-table"
          v-loading="dataListLoading"
          @selection-change="selectionChangeHandler"
        >
          <el-table-column
            v-if="contents.tableSelection"
            type="selection"
            width="48"
            align="center"
          ></el-table-column>

          <el-table-column
            label="索引"
            v-if="contents.tableIndex"
            type="index"
            width="64"
            align="center"
          >
            <template slot-scope="scope">
              <span class="index-badge">{{ scope.$index + 1 }}</span>
            </template>
          </el-table-column>

          <el-table-column prop="xiquName" label="知识名称" min-width="200">
            <template slot-scope="scope">
              <div class="title-cell">
                <i class="el-icon-collection-tag"></i>
                <span class="text-ellipsis">{{ scope.row.xiquName }}</span>
              </div>
            </template>
          </el-table-column>

          <el-table-column
            prop="xiquPhoto"
            label="知识图片"
            width="120"
            align="center"
          >
            <template slot-scope="scope">
              <div class="image-preview">
                <img
                  v-if="scope.row.xiquPhoto"
                  :src="$base.url + scope.row.xiquPhoto"
                  class="table-image"
                />
                <span v-else class="image-placeholder">暂无图片</span>
              </div>
            </template>
          </el-table-column>

          <el-table-column prop="xiquTypes" label="知识类型" width="140">
            <template slot-scope="scope">
              <el-tag type="warning">{{ scope.row.xiquValue }}</el-tag>
            </template>
          </el-table-column>

          <el-table-column prop="yonghuName" label="收藏用户" width="120">
            <template slot-scope="scope">
              <el-tag type="info">
                <i class="el-icon-user-solid"></i>
                {{ scope.row.yonghuName }}
              </el-tag>
            </template>
          </el-table-column>

          <el-table-column
            prop="xiquCollectionTypes"
            label="收藏类型"
            width="120"
          >
            <template slot-scope="scope">
              <el-tag
                :type="scope.row.xiquCollectionTypes == 1 ? 'success' : 'info'"
                effect="light"
              >
                {{ scope.row.xiquCollectionValue }}
              </el-tag>
            </template>
          </el-table-column>

          <el-table-column prop="insertTime" label="收藏时间" width="160">
            <template slot-scope="scope">
              <div class="time-cell">
                <i class="el-icon-time"></i>
                {{ scope.row.insertTime }}
              </div>
            </template>
          </el-table-column>

          <el-table-column
            label="操作"
            width="160"
            fixed="right"
            align="center"
          >
            <template slot-scope="scope">
              <div class="table-actions">
                <el-tooltip
                  content="查看详情"
                  v-if="isAuth('xiquCollection', '查看')"
                >
                  <el-button
                    type="text"
                    icon="el-icon-document"
                    class="action-btn"
                    @click="addOrUpdateHandler(scope.row.id, 'info')"
                  ></el-button>
                </el-tooltip>

                <el-tooltip
                  content="编辑信息"
                  v-if="isAuth('xiquCollection', '修改')"
                >
                  <el-button
                    type="text"
                    icon="el-icon-edit"
                    class="action-btn"
                    @click="addOrUpdateHandler(scope.row.id)"
                  ></el-button>
                </el-tooltip>

                <el-tooltip
                  content="取消收藏"
                  v-if="isAuth('xiquCollection', '删除')"
                >
                  <el-button
                    type="text"
                    icon="el-icon-delete"
                    class="action-btn danger"
                    @click="deleteHandler(scope.row.id)"
                  ></el-button>
                </el-tooltip>
              </div>
            </template>
          </el-table-column>
        </el-table>

        <!-- 分页 -->
        <div class="modern-pagination">
          <el-pagination
            background
            :page-sizes="[10, 20, 50, 100]"
            :page-size="Number(contents.pageEachNum)"
            layout="total, sizes, prev, pager, next, jumper"
            :total="totalPage"
            @size-change="sizeChangeHandle"
            @current-change="currentChangeHandle"
          ></el-pagination>
        </div>
      </div>
    </div>
    <!-- 添加/修改页面  将父组件的search方法传递给子组件-->
    <add-or-update
      v-if="addOrUpdateFlag"
      :parent="this"
      ref="addOrUpdate"
    ></add-or-update>

    <el-dialog
      title="打印"
      :visible.sync="printVisiable"
      width="500px"
      class="modern-dialog"
    >
      <el-form ref="printContent" :model="printFrom" label-width="auto">
        <el-form-item label="发件人">
          <div style="display: flex">
            <el-input v-model="printFrom.kuaidiFajianName" disabled></el-input>
            :
            <el-input
              v-model="printFrom.kuaidiFajianShoujihao"
              disabled
            ></el-input>
          </div>
        </el-form-item>
        <el-form-item label="发件人地址">
          <el-input v-model="printFrom.kuaidiFajianAddress" disabled></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="printContent()" icon="el-icon-printer" type="success"
          >打印</el-button
        >
        <el-button @click="printVisiable = false">关闭</el-button>
      </span>
    </el-dialog>

    <el-dialog
      title="统计报表"
      :visible.sync="chartVisiable"
      width="80%"
      class="modern-dialog"
    >
      <el-date-picker v-model="echartsDate" type="year" placeholder="选择年">
      </el-date-picker>
      <el-button @click="chartDialog()">查询</el-button>
      <div id="statistic" style="width: 100%; height: 600px"></div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="chartVisiable = false">关闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import AddOrUpdate from "./add-or-update";
import styleJs from "../../../utils/style.js";
import utilsJs, {
  getYearFormat,
  getMonthFormat,
  getDateFormat,
  getDatetimeFormat,
} from "../../../utils/utils.js";

export default {
  data() {
    return {
      //打印开始
      printFrom: {
        name1: "",
      },
      printVisiable: false,
      //打印结束
      searchForm: {
        key: "",
      },
      sessionTable: "", //登录账户所在表名
      role: "", //权限
      userId: "", //当前登录人的id
      //级联表下拉框搜索条件
      xiquTypesSelectSearch: [],
      //当前表下拉框搜索条件
      form: {
        id: null,
        xiquId: null,
        yonghuId: null,
        xiquCollectionTypes: null,
        insertTime: null,
        createTime: null,
      },
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      showFlag: true,
      sfshVisiable: false,
      shForm: {},
      chartVisiable: false,
      echartsDate: new Date(), //echarts的时间查询字段
      addOrUpdateFlag: false,
      contents: null,
      layouts: "",

      //导出excel
      json_fields: {
        //级联表字段
        中医药文化知识名称: "xiquName",
        中医药文化知识编号: "xiquUuidNumber",
        中医药文化知识照片: "xiquPhoto",
        发源地: "xiquAddress",
        中医药文化知识文件: "xiquFile",
        中医药文化知识音频: "xiquMusic",
        中医药文化知识视频: "xiquVideo",
        中医药文化知识类型: "xiquTypes",
        赞: "zanNumber",
        踩: "caiNumber",
        中医药文化知识热度: "xiquClicknum",
        是否上架: "shangxiaTypes",
        用户姓名: "yonghuName",
        用户手机号: "yonghuPhone",
        用户身份证号: "yonghuIdNumber",
        用户头像: "yonghuPhoto",
        用户邮箱: "yonghuEmail",
        //本表字段
        类型: "xiquCollectionValue",
        收藏时间: "insertTime",
      },
    };
  },
  created() {
    this.contents = styleJs.listStyle();
    this.init();
    this.getDataList();
    this.contentStyleChange();
  },
  mounted() {
    //获取当前登录用户的信息
    this.sessionTable = this.$storage.get("sessionTable");
    this.role = this.$storage.get("role");
    this.userId = this.$storage.get("userId");
  },
  filters: {
    htmlfilter: function (val) {
      return val.replace(/<[^>]*>/g).replace(/undefined/g, "");
    },
  },
  components: {
    AddOrUpdate,
  },
  computed: {
    getActionUrl: function () {
      return `/` + this.$base.name + `/file/upload`;
    },
  },
  methods: {
    chartDialog() {
      let _this = this;
      let params = {
        dateFormat: "%Y", //%Y-%m
        riqi: getYearFormat(_this.echartsDate), //年
        // riqi :getMonthFormat(_this.echartsDate),//年月
        thisTable: {
          //当前表
          tableName: "xiqu_collection", //当前表表名,
          sumColum: "xiqu_collection_number", //求和字段
          date: "insert_time", //分组日期字段
          // string : 'xiqu_collection_name',//分组字符串字段
          // types : 'xiqu_collection_types',//分组下拉框字段
        },
        // joinTable : {//级联表（可以不存在）
        //     tableName :'yonghu',//级联表表名
        //     // date : 'insert_time',//分组日期字段
        //     string : 'yonghu_name',//分组字符串字段
        //     // types : 'yonghu_types',//分组下拉框字段
        // }
      };
      _this.chartVisiable = true;
      _this.$nextTick(() => {
        var statistic = this.$echarts.init(
          document.getElementById("statistic"),
          "macarons"
        );
        this.$http({
          url: "barSum", //barCountOne barCountTwo barSumOne barSumTwo
          method: "get",
          params: params,
        }).then(({ data }) => {
          if (data && data.code === 0) {
            let yAxisName = "数值"; //y轴
            let xAxisName = "月份"; //x轴
            let series = []; //具体数据值
            data.data.yAxis.forEach(function (item, index) {
              //点击可关闭的按钮字符串在后台方法中
              let tempMap = {};
              tempMap.name = data.data.legend[index];
              tempMap.type = "bar";
              tempMap.data = item;
              series.push(tempMap);
            });

            var option = {
              tooltip: {
                trigger: "axis",
                axisPointer: {
                  type: "cross",
                  crossStyle: {
                    color: "#999",
                  },
                },
              },
              toolbox: {
                feature: {
                  // dataView: { show: true, readOnly: false },  // 数据查看
                  magicType: { show: true, type: ["line", "bar"] }, //切换图形展示方式
                  // restore: { show: true }, // 刷新
                  saveAsImage: { show: true }, //保存
                },
              },
              legend: {
                data: data.data.legend, //标题  可以点击导致某一列数据消失
              },
              xAxis: [
                {
                  type: "category",
                  axisLabel: { interval: 0 },
                  name: xAxisName,
                  data: data.data.xAxis,
                  axisPointer: {
                    type: "shadow",
                  },
                },
              ],
              yAxis: [
                {
                  type: "value", //不能改
                  name: yAxisName, //y轴单位
                  axisLabel: {
                    formatter: "{value}", // 后缀
                  },
                },
              ],
              series: series, //具体数据
            };
            statistic.setOption(option, true);
            window.onresize = function () {
              statistic.resize();
            };
          } else {
            this.$message({
              message: "报表未查询到数据",
              type: "success",
              duration: 1500,
              onClose: () => {
                this.search();
              },
            });
          }
        });
      });
      ////饼状图
      //_this.chartVisiable = true;
      // this.$nextTick(()=>{
      //     var statistic = this.$echarts.init(document.getElementById("statistic"),'macarons');
      //     let params = {
      //         tableName: "xiqu_collection",
      //         groupColumn: "xiqu_collection_types",
      //     }
      //     this.$http({
      //         url: "newSelectGroupCount",//pieSum pieCount
      //         method: "get",
      //         params: params
      //     }).then(({data}) => {
      //         if (data && data.code === 0) {
      //             let res = data.data;
      //             let xAxis = [];
      //             let yAxis = [];
      //             let pArray = []
      //             var option = {};
      //             for(let i=0;i<res.length;i++){
      //                 xAxis.push(res[i].name);
      //                 yAxis.push(res[i].value);
      //                 pArray.push({
      //                     value: res[i].value,
      //                     name: res[i].name
      //                 })
      //                 option = {
      //                     title: {
      //                         text: '保险合同类型统计',
      //                         left: 'center'
      //                     },
      //                     tooltip: {
      //                         trigger: 'item',
      //                         formatter: '{b} : {c} ({d}%)'
      //                     },
      //                     legend: {
      //                         orient: 'vertical',
      //                         left: 'left'
      //                     },
      //                     series: [
      //                         {
      //                             type: 'pie',
      //                             radius: '55%',
      //                             center: ['50%', '60%'],
      //                             data: pArray,
      //                             emphasis: {
      //                                 itemStyle: {
      //                                     shadowBlur: 10,
      //                                     shadowOffsetX: 0,
      //                                     shadowColor: 'rgba(0, 0, 0, 0.5)'
      //                                 }
      //                             }
      //                         }
      //                     ]
      //                 };
      //             }
      //             statistic.setOption(option,true);
      //             window.onresize = function() {
      //                 statistic.resize();
      //             };
      //         }
      //     });
      // })
    },
    contentStyleChange() {
      this.contentSearchStyleChange();
      this.contentBtnAdAllStyleChange();
      this.contentSearchBtnStyleChange();
      this.contentTableBtnStyleChange();
      this.contentPageStyleChange();
    },
    contentSearchStyleChange() {
      this.$nextTick(() => {
        document
          .querySelectorAll(".form-content .slt .el-input__inner")
          .forEach((el) => {
            let textAlign = "left";
            if (this.contents.inputFontPosition == 2) textAlign = "center";
            if (this.contents.inputFontPosition == 3) textAlign = "right";
            el.style.textAlign = textAlign;
            el.style.height = this.contents.inputHeight;
            el.style.lineHeight = this.contents.inputHeight;
            el.style.color = this.contents.inputFontColor;
            el.style.fontSize = this.contents.inputFontSize;
            el.style.borderWidth = this.contents.inputBorderWidth;
            el.style.borderStyle = this.contents.inputBorderStyle;
            el.style.borderColor = this.contents.inputBorderColor;
            el.style.borderRadius = this.contents.inputBorderRadius;
            el.style.backgroundColor = this.contents.inputBgColor;
          });
        if (this.contents.inputTitle) {
          document
            .querySelectorAll(".form-content .slt .el-form-item__label")
            .forEach((el) => {
              el.style.color = this.contents.inputTitleColor;
              el.style.fontSize = this.contents.inputTitleSize;
              el.style.lineHeight = this.contents.inputHeight;
            });
        }
        setTimeout(() => {
          document
            .querySelectorAll(".form-content .slt .el-input__prefix")
            .forEach((el) => {
              el.style.color = this.contents.inputIconColor;
              el.style.lineHeight = this.contents.inputHeight;
            });
          document
            .querySelectorAll(".form-content .slt .el-input__suffix")
            .forEach((el) => {
              el.style.color = this.contents.inputIconColor;
              el.style.lineHeight = this.contents.inputHeight;
            });
          document
            .querySelectorAll(".form-content .slt .el-input__icon")
            .forEach((el) => {
              el.style.lineHeight = this.contents.inputHeight;
            });
        }, 10);
      });
    },
    // 搜索按钮
    contentSearchBtnStyleChange() {
      this.$nextTick(() => {
        document
          .querySelectorAll(".form-content .slt .el-button--success")
          .forEach((el) => {
            el.style.height = this.contents.searchBtnHeight;
            el.style.color = this.contents.searchBtnFontColor;
            el.style.fontSize = this.contents.searchBtnFontSize;
            el.style.borderWidth = this.contents.searchBtnBorderWidth;
            el.style.borderStyle = this.contents.searchBtnBorderStyle;
            el.style.borderColor = this.contents.searchBtnBorderColor;
            el.style.borderRadius = this.contents.searchBtnBorderRadius;
            el.style.backgroundColor = this.contents.searchBtnBgColor;
          });
      });
    },
    // 新增、批量删除
    contentBtnAdAllStyleChange() {
      this.$nextTick(() => {
        document
          .querySelectorAll(".form-content .ad .el-button--success")
          .forEach((el) => {
            el.style.height = this.contents.btnAdAllHeight;
            el.style.color = this.contents.btnAdAllAddFontColor;
            el.style.fontSize = this.contents.btnAdAllFontSize;
            el.style.borderWidth = this.contents.btnAdAllBorderWidth;
            el.style.borderStyle = this.contents.btnAdAllBorderStyle;
            el.style.borderColor = this.contents.btnAdAllBorderColor;
            el.style.borderRadius = this.contents.btnAdAllBorderRadius;
            el.style.backgroundColor = this.contents.btnAdAllAddBgColor;
          });
        document
          .querySelectorAll(".form-content .ad .el-button--danger")
          .forEach((el) => {
            el.style.height = this.contents.btnAdAllHeight;
            el.style.color = this.contents.btnAdAllDelFontColor;
            el.style.fontSize = this.contents.btnAdAllFontSize;
            el.style.borderWidth = this.contents.btnAdAllBorderWidth;
            el.style.borderStyle = this.contents.btnAdAllBorderStyle;
            el.style.borderColor = this.contents.btnAdAllBorderColor;
            el.style.borderRadius = this.contents.btnAdAllBorderRadius;
            el.style.backgroundColor = this.contents.btnAdAllDelBgColor;
          });
        document
          .querySelectorAll(".form-content .ad .el-button--warning")
          .forEach((el) => {
            el.style.height = this.contents.btnAdAllHeight;
            el.style.color = this.contents.btnAdAllWarnFontColor;
            el.style.fontSize = this.contents.btnAdAllFontSize;
            el.style.borderWidth = this.contents.btnAdAllBorderWidth;
            el.style.borderStyle = this.contents.btnAdAllBorderStyle;
            el.style.borderColor = this.contents.btnAdAllBorderColor;
            el.style.borderRadius = this.contents.btnAdAllBorderRadius;
            el.style.backgroundColor = this.contents.btnAdAllWarnBgColor;
          });
      });
    },
    // 表格
    rowStyle({ row, rowIndex }) {
      if (rowIndex % 2 == 1) {
        if (this.contents.tableStripe) {
          return { color: this.contents.tableStripeFontColor };
        }
      } else {
        return "";
      }
    },
    cellStyle({ row, rowIndex }) {
      if (rowIndex % 2 == 1) {
        if (this.contents.tableStripe) {
          return { backgroundColor: this.contents.tableStripeBgColor };
        }
      } else {
        return "";
      }
    },
    headerRowStyle({ row, rowIndex }) {
      return { color: this.contents.tableHeaderFontColor };
    },
    headerCellStyle({ row, rowIndex }) {
      return { backgroundColor: this.contents.tableHeaderBgColor };
    },
    // 表格按钮
    contentTableBtnStyleChange() {
      // this.$nextTick(()=>{
      //   setTimeout(()=>{
      //     document.querySelectorAll('.table-content .tables .el-table__body .el-button--success').forEach(el=>{
      //       el.style.height = this.contents.tableBtnHeight
      //       el.style.color = this.contents.tableBtnDetailFontColor
      //       el.style.fontSize = this.contents.tableBtnFontSize
      //       el.style.borderWidth = this.contents.tableBtnBorderWidth
      //       el.style.borderStyle = this.contents.tableBtnBorderStyle
      //       el.style.borderColor = this.contents.tableBtnBorderColor
      //       el.style.borderRadius = this.contents.tableBtnBorderRadius
      //       el.style.backgroundColor = this.contents.tableBtnDetailBgColor
      //     })
      //     document.querySelectorAll('.table-content .tables .el-table__body .el-button--primary').forEach(el=>{
      //       el.style.height = this.contents.tableBtnHeight
      //       el.style.color = this.contents.tableBtnEditFontColor
      //       el.style.fontSize = this.contents.tableBtnFontSize
      //       el.style.borderWidth = this.contents.tableBtnBorderWidth
      //       el.style.borderStyle = this.contents.tableBtnBorderStyle
      //       el.style.borderColor = this.contents.tableBtnBorderColor
      //       el.style.borderRadius = this.contents.tableBtnBorderRadius
      //       el.style.backgroundColor = this.contents.tableBtnEditBgColor
      //     })
      //     document.querySelectorAll('.table-content .tables .el-table__body .el-button--danger').forEach(el=>{
      //       el.style.height = this.contents.tableBtnHeight
      //       el.style.color = this.contents.tableBtnDelFontColor
      //       el.style.fontSize = this.contents.tableBtnFontSize
      //       el.style.borderWidth = this.contents.tableBtnBorderWidth
      //       el.style.borderStyle = this.contents.tableBtnBorderStyle
      //       el.style.borderColor = this.contents.tableBtnBorderColor
      //       el.style.borderRadius = this.contents.tableBtnBorderRadius
      //       el.style.backgroundColor = this.contents.tableBtnDelBgColor
      //     })
      //   }, 50)
      // })
    },
    // 分页
    contentPageStyleChange() {
      let arr = [];
      if (this.contents.pageTotal) arr.push("total");
      if (this.contents.pageSizes) arr.push("sizes");
      if (this.contents.pagePrevNext) {
        arr.push("prev");
        if (this.contents.pagePager) arr.push("pager");
        arr.push("next");
      }
      if (this.contents.pageJumper) arr.push("jumper");
      this.layouts = arr.join();
      this.contents.pageEachNum = 10;
    },

    init() {},
    search() {
      this.pageIndex = 1;
      this.getDataList();
    },
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true;
      let params = {
        page: this.pageIndex,
        limit: this.pageSize,
        sort: "id",
        xiquCollectionTypes: 1,
      };

      if (
        this.searchForm.xiquName != "" &&
        this.searchForm.xiquName != undefined
      ) {
        params["xiquName"] = "%" + this.searchForm.xiquName + "%";
      }

      if (
        this.searchForm.xiquTypes != "" &&
        this.searchForm.xiquTypes != undefined
      ) {
        params["xiquTypes"] = this.searchForm.xiquTypes;
      }

      if (
        this.searchForm.yonghuName != "" &&
        this.searchForm.yonghuName != undefined
      ) {
        params["yonghuName"] = "%" + this.searchForm.yonghuName + "%";
      }

      params["xiquCollectionDelete"] = 1; // 逻辑删除字段 1 未删除 2 删除

      this.$http({
        url: "xiquCollection/page",
        method: "get",
        params: params,
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.dataList = data.data.list;
          this.totalPage = data.data.total;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });

      //查询级联表搜索条件所有列表
      this.$http({
        url: "dictionary/page?dicCode=xiqu_types&page=1&limit=100",
        method: "get",
        page: 1,
        limit: 100,
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.xiquTypesSelectSearch = data.data.list;
        }
      });
      //查询当前表搜索条件所有列表
    },
    //每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    },
    // 多选
    selectionChangeHandler(val) {
      this.dataListSelections = val;
    },
    // 添加/修改
    addOrUpdateHandler(id, type) {
      this.showFlag = false;
      this.addOrUpdateFlag = true;
      this.crossAddOrUpdateFlag = false;
      if (type != "info") {
        type = "else";
      }
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id, type);
      });
    },
    // 下载
    download(file) {
      window.open(" ${file} ");
    },
    // 弹出打印模态框
    dayinOpen(item) {
      let _this = this;
      _this.printVisiable = true;
      _this.printFrom = item;
    },
    // 打印内容
    printContent() {
      let _this = this;
      _this.$print(_this.$refs.printContent);
      _this.printVisiable = false;
    },
    // 删除
    deleteHandler(id) {
      var ids = id
        ? [Number(id)]
        : this.dataListSelections.map((item) => {
            return Number(item.id);
          });

      this.$confirm(`确定进行[${id ? "删除" : "批量删除"}]操作?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.$http({
          url: "xiquCollection/delete",
          method: "post",
          data: ids,
        }).then(({ data }) => {
          if (data && data.code === 0) {
            this.$message({
              message: "操作成功",
              type: "success",
              duration: 1500,
              onClose: () => {
                this.search();
              },
            });
          } else {
            this.$message.error(data.msg);
          }
        });
      });
    },
    // 导入功能上传文件成功后调用导入方法
    xiquCollectionUploadSuccess(data) {
      let _this = this;
      _this
        .$http({
          url: "xiquCollection/batchInsert?fileName=" + data.file,
          method: "get",
        })
        .then(({ data }) => {
          if (data && data.code === 0) {
            _this.$message({
              message: "导入中医药文化知识收藏数据成功",
              type: "success",
              duration: 1500,
              onClose: () => {
                _this.search();
              },
            });
          } else {
            _this.$message.error(data.msg);
          }
        });
    },
    // 导入功能上传文件失败后调用导入方法
    xiquCollectionUploadError(data) {
      this.$message.error("上传失败");
    },
    formatTime(time) {
      return dayjs(time).format("YYYY-MM-DD HH:mm");
    },
    //无用
    wuyong(id) {
      let _this = this;
      _this
        .$confirm(`确定    操作?`, "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
        .then(() => {
          _this
            .$http({
              url: "xiquCollection/update",
              method: "post",
              data: {
                id: id,
                //                            xiquCollectionTypes:xiquCollectionTypes,
              },
            })
            .then(({ data }) => {
              if (data && data.code === 0) {
                _this.$message({
                  message: "操作成功",
                  type: "success",
                  duration: 1500,
                  onClose: () => {
                    _this.search();
                  },
                });
              } else {
                _this.$message.error(data.msg);
              }
            });
        });
    },
  },
};
</script>
<style scoped>
.modern-list-container {
  --primary-color: #3a8e5c;
  --secondary-color: #d4b266;
  --success-color: #67c23a;
  --warning-color: #e6a23c;
  --danger-color: #f56c6c;
  --info-color: #909399;
  --border-color: #ebeef5;
  --bg-base: #f5f7fa;
  --radius-md: 8px;
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
}
.modern-data-table::v-deep {
  --el-table-header-background-color: rgba(245, 247, 250, 0.9);
  --el-table-border-color: var(--border-color);
  /* color: 333; */
}
.modern-list-content {
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
}

.modern-toolbar {
  padding: 20px 24px;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  border-bottom: 1px solid var(--border-color);
}

.search-group {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-grow: 1;
}

.modern-search-input::v-deep .el-input__inner {
  height: 40px;
  border-radius: 20px;
  padding-left: 40px;
  border: 1px solid var(--primary-color);
}

.modern-select::v-deep .el-input__inner {
  border-radius: 20px;
  padding-left: 15px;
}
.modern-search-panel {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-color);
}
.search-group {
  display: flex;
  justify-content: center;
  gap: 16px;
  align-items: center;
  width: 90vw;
}
.action-group {
  width: 90vw;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.action-toolbar {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-color);
}
.modern-input {
  width: 250px;
}
.modern-input::v-deep .el-input__inner {
  border-radius: 20px;
  /* padding-left: 15px; */
}
.image-preview {
  width: 80px;
  height: 80px;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-base);
  margin: 0 auto;
}

.table-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.table-image:hover {
  transform: scale(1.1);
}

.time-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--info-color);
  font-size: 13px;
}

.table-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.action-btn {
  padding: 8px;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.action-btn:hover {
  background: rgba(58, 142, 92, 0.1);
  color: var(--primary-color);
}

.action-btn.danger:hover {
  color: var(--danger-color);
  background: rgba(245, 108, 108, 0.1);
}

.modern-pagination {
  padding: 16px;
  background: rgba(245, 247, 250, 0.8);
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

@media (max-width: 768px) {
  .search-group {
    flex-wrap: wrap;
  }

  .modern-search-input,
  .modern-select {
    width: 100%;
  }

  .action-group {
    justify-content: center;
  }

  .image-preview {
    width: 60px;
    height: 60px;
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modern-list-content {
  animation: fadeIn 0.4s ease;
}
</style>
